package com.zretc.task;


import com.zretc.dao.OrdersMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author  周文涛
 * 定时判断订单是否超时
 */
@Component
public class OrdersTimeOutTask{
    private static final Logger LOGGER = LoggerFactory.getLogger(OrdersTimeOutTask.class);

    @Autowired
    private OrdersMapper ordersMapper;

    @Scheduled(cron = "0 * * * * ? ")
    public void timeout(){
        //查找所有超时订单
        List<String> timeOutOrders = ordersMapper.getTimeOutOrders();
        // 全部状态设置为已超时
        LOGGER.debug("==============执行订单超时处理方法=================");
        for (String timeOutOrder : timeOutOrders) {
            ordersMapper.updateStatus(timeOutOrder,4);
        }
    }
}
